import {Logger} from './logger';
import * as Cookies from 'js-cookie';
import {CookieAttributes} from 'js-cookie';
import {environment} from '../../../environments/environment';

export class CookieHelper {

  public static clearCookies(): void {
    const cookies: { [key: string]: string } = Cookies.get();
    if (cookies) {
      for (const key of Object.keys(cookies)) {
        if (key.toLowerCase().startsWith('dhl-')) {
          Cookies.remove(key);
          Logger.log(`[CookieHelper] Cookie: ${key} removed.`);
        }
      }
    }
  }

  public static hasLoggedIn(): boolean {
    return !!CookieHelper.get(environment.tokenCookieKey);
  }

  public static get(name: string): string | undefined {
    return Cookies.get(name);
  }

  public static set(name: string, value: string, options?: CookieAttributes): void {
    Cookies.set(name, value, options);
  }


}
